package com.zhong.auth.common.entity;


import com.zhong.auth.common.enums.ResultCodesEnum;
import lombok.Data;

@Data
public class Result<T> {
    private boolean success;
    private Integer code;
    private String message;
    private T data;

    public static <T> Result ok(){
        Result<T> result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodesEnum.SUCCESS.getCode());
        result.setMessage(ResultCodesEnum.SUCCESS.getDesc());
        return result;
    }

    public static <T> Result ok(T data){
        Result<T>  result = new Result<>();
        result.setSuccess(true);
        result.setCode(ResultCodesEnum.SUCCESS.getCode());
        result.setMessage(ResultCodesEnum.SUCCESS.getDesc());
        result.setData(data);
        return result;
    }

    public static <T>  Result<T> fail(){
        Result<T>  result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodesEnum.FAIL.getCode());
        result.setMessage(ResultCodesEnum.FAIL.getDesc());
        return result;
    }

    public static<T> Result fail(T data){
        Result<T> result = new Result<>();
        result.setSuccess(false);
        result.setCode(ResultCodesEnum.FAIL.getCode());
        result.setMessage(ResultCodesEnum.FAIL.getDesc());
        result.setData(data);
        return result;
    }
}
